! function () {
    var files = [
      //'eln178',
    //'eln176',
      //'eln202',
      //'eln205',
      'eln206',
      'eln153',
      //'eln207',
      //'eln204',
     //'eln200',
      //'eln203',
    'eln177',
      //'eln201',
    ];
    var file = location.pathname.substr(1, location.pathname.length),
        hostPrefix = location.host.substr(0, location.host.indexOf('.')),
        referrer = /eln\d*/.exec(document.referrer),
        path,
        isok = false,
        index = 0,
        hb = true,
        attr = {
            attr: '',
            add: function (key, value) {
                !!!this.attr && (this.attr = '');
                this.attr += this.attr[0] === '?' ? '&' : '?';
                this.attr += key + '=' + value;
            },
            remove: function (key) {
                var pre = nxt = '',
                    str = this.attr;

                pre = str.substr(0, str.indexOf(key) - 1);
                nxt = str.substr(str.indexOf(key));
                !!nxt && (nxt = nxt.substr(nxt.indexOf('&') + 1));

                this.attr = pre + '&' + nxt;
            },
        },
        pars;
    file = /eln\d+/.exec(location.href);
    !!file && (file = file[0])
    referrer = referrer ? referrer[0] : referrer;
    pars = (
        (function () {
            var search = location.search
            var pars = search.substr(1, search.length).split('&')
            pars.forEach(function (a, b) {
                var map = a.split('=')
                pars[b] = {
                    key: map[0],
                    value: map[1]
                }
            })
            pars.getVal = function (key) {
                try {
                    return this.filter(function (a) {
                        if (key === a.key) {
                            return true
                        }
                    })[0].value
                } catch (err) {
                    return ''
                }
            }
            return pars
        })()
    );

    for (var q = 0, o = files[q]; q < files.length; q++, o = files[q]) {
        var referre = pars.getVal('referre');
        if (!isok) {
            o === file ? (
                index = q,
                referre ? referre === files[q + 1] ? files.splice(q + 1, 1) : attr = "?referre=" + referre : '',
                (q + 1) != files.length ? (
                    path = files[q + 1],
                    isok = true
                ) : path = files[0]
            ) : path = files[0];
        }
    }


    // common check open
    if (!!(skip = pars.getVal('skip'))) {
        // 跳过某些广告
        if (files[index + 1] === skip) {
            // 跳到下一个广告
            var skipAd = index + 2;
            (files.length - 1) < skipAd && (skipAd = 0);
            path = files[skipAd];
        } else {
            attr.add('skip', skip);
        }
    }
    if (!!pars.getVal('hb')) {
        hb = false
    }
    function myajax(url, callback, isJSON = false) {
        var request = new XMLHttpRequest();
        request.open('get', url, true);
        request.send();
        request.onreadystatechange = function () {
            if (request.readyState === 4 && request.status === 200) {
                isJSON ? callback(JSON.parse(request.responseText)) : callback(request.responseText);
            }
        }
    }
    function fetchAdPage() {
        var preAdUrl = window['back_url'] || window['adurl'];
        var adUrl = "";
        if (preAdUrl) {
          
            var file1=/eln\d+/.exec(preAdUrl);
            if (file1) {
            file1 = file1[0];
            }
            var u=0;
            for (var i=0;i<files.length;i++){
              if (file1==files[i]){
                  u=i+1;
                break;
              }
            }
            path=files[u];
            //path = files[1],
            adUrl = preAdUrl.replace(/eln\d+/, path.replace('ad', 'eln')) + attr.attr;
        } else {
            adUrl = location.origin + location.pathname.replace(/eln\d+/, path.replace('ad', 'eln')) + attr.attr;
        }
        window['back_url'] = adUrl;
        myajax(adUrl, function(t) {
          	console.log(adUrl);
            window.ggview = t;
        });
    }

    fetchAdPage();

    window.onhashchange = function () {
        var ac = document.createElement('a')
        if (hb) {
            // 
        }
        if (window['ggview']) {
            document.write('');
            document.write(window.ggview); document.close();window.scrollTo(0,0);
            return;
        }
    }

}()

setTimeout(function () {
    history.pushState(history.length + 1, "message", "#" + (new Date).getTime());
}, 100)